#include "replacefile.h"

#include <QLayout>
#include <QLabel>
#include <QPushButton>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QHBoxLayout>

replacefile::replacefile(QWidget *parent) : QWidget(parent)
{
    this->setMinimumSize(400,300);
    this->setMaximumSize(400,300);

    QPoint globalPos = parentWidget->mapToGlobal(QPoint(0,0));//父窗口绝对坐标
    int x = globalPos.x() + (parentWidget->width() - this->width()) / 2;//x坐标
    int y = globalPos.y() + (parentWidget->height() - this->height()) / 2;//y坐标
    this->move(x, y);//窗口移动

    this->setWindowFlags(
    Qt::Window \
    |Qt::FramelessWindowHint\
    |Qt::WindowMinimizeButtonHint\
    |Qt::WindowMaximizeButtonHint);

    QVBoxLayout *lyt_main = new QVBoxLayout(this);
    QHBoxLayout *lyt_head = new QHBoxLayout(this);
    QVBoxLayout *lyt_body = new QVBoxLayout(this);
    QHBoxLayout *lyt_body_1 = new QHBoxLayout(this);
    QHBoxLayout *lyt_body_2 = new QHBoxLayout(this);
    QHBoxLayout *lyt_body_3 = new QHBoxLayout(this);
    QHBoxLayout *lyt_body_4 = new QHBoxLayout(this);
    QHBoxLayout *lyt_body_5 = new QHBoxLayout(this);

    QLabel *lbl_load = new QLabel(this);
    QLabel *lbl_file  = new QLabel(this);

    QLineEdit *le_file = new QLineEdit(this);
    QPushButton *btn_file_chooses = new QPushButton(this);
    QPushButton *btn_load = new QPushButton(this);

    QPushButton *btn_close = new QPushButton(this);

    //添加顶部布局
    lyt_head->addWidget(lbl_load);
    lyt_head->addWidget(btn_close);

    //设置内容布局
    lyt_body_1->addWidget(lbl_file);
    lyt_body_2->addWidget(le_file);
    lyt_body_5->addWidget(btn_load);
    lyt_body->addLayout(lyt_body_1);
    lyt_body->addLayout(lyt_body_2);
    lyt_body->addLayout(lyt_body_3);
    lyt_body->addLayout(lyt_body_4);
    lyt_body->addLayout(lyt_body_5);

    //添加整体布局
    lyt_main->addLayout(lyt_head);
    lyt_main->addLayout(lyt_body);

    if(LangureStu)
    {
        lbl_load->setText("Import");
        lbl_file->setText("Files Paths");
        btn_load->setText("Import");
        btn_file_chooses->setText("Chooses");
    }
    else
    {
        lbl_load->setText("导入");
        lbl_file->setText("升级文件目录");
        btn_load->setText("导入");
        btn_file_chooses->setText("选择");
    }

    QIcon CloseIcon(":/image/close.png");
    btn_close->setIcon(CloseIcon);
}

replacefile::~replacefile()
{
    delete this;
}
